<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Insert title here</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/AdminComment.css" rel="stylesheet">
    <script src="../js/jquery-1.11.3.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script type="text/javascript">
    </script>
    <style>
    	.pageNav{
    		margin-left:600px;
    	}
    </style>
    <script>
    	$(function(){
    		$("#categoryname").blur(function(){
    			$.getJSON("commentGetCake?id="+$(this).val(),function(json){
    				$("#cakename").empty();
    				for(var i=0; i<json.length; i++){
        				var c = json[i];
        				var line = "<option value="+c.id+">"+c.name+"</option>";
        				$("#cakename").append(line);
        			}
    			})
    		})
    	})
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">21Cake</a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">首页 <span class="sr-only">(current)</span></a></li>  
                    </ul>
                    <form class="navbar-form navbar-left" action="comm.html">
                    	<select id="categoryname" name="categoryid" class="form-control">
                    		<option value="">商品分类</option>
                    		<c:forEach var="cg" items="${categories}">
                    			<c:if test="${cg.id == categoryid}">
                                	<option value="${cg.id}" selected="selected">${cg.name}</option>
                                </c:if>
                                <c:if test="${cg.id != categoryid}">
                                	<option value="${cg.id}">${cg.name}</option>
                                </c:if>
                            </c:forEach>
                    	</select>
                    	<select id="cakename" name="cid" class="form-control">
                    		<c:if test="${cakes!=null}">
                    			<c:forEach var="cake" items="${cakes}">
                    				<c:if test="${cake.id == cid}">
                    					<option value="${cake.id}" selected="selected">${cake.name}</option>
                    				</c:if>
                    				<c:if test="${cake.id != cid}">
                    					<option value="${cake.id}">${cake.name}</option>
                    				</c:if>
                    			</c:forEach>
                    		</c:if>
                    	</select>
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="${title}" name="title">
                        </div>
                        <button type="submit" class="btn btn-default search">查询</button>
                    </form>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="adminLogin">注销</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="row">
        <div class="col-md-2">
            <ul class="list-group">
                 <li class="list-group-item"><a href="orderlist.html">订单列表</a></li>
                <li class="list-group-item"><a href="userlist.jsp">用户列表</a></li>
                <li class="list-group-item"><a href="cakelist.html">商品列表</a></li>
                <li class="list-group-item"><a href="comm.html">评论列表</a></li>
            </ul>
        </div>
        <div class="col-md-10">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <td width="10%">用户名</td>
                        <td width="20%">商品名</td>
                        <td width="5%">评分</td>
                        <td width="45%">评论</td>
                        <td width="10%">评论时间</td>
                        <td width="10%">操作</td>
                    </tr>
                </thead>
                <tbody>
                	<c:forEach var="c" items="${comments}">
                		<tr>
                        <td>${c.username}</td>
                        <td>${c.name}</td>
                        <td>${c.score}</td>
                        <td>${c.content}</td>
                        <td>${c.date}</td>
                        <td>
                            <a href="comment.html?did=${c.id}">删除</a>
                        </td>
                    </tr>
                	</c:forEach>
                </tbody>
            </table>
        </div>
        <div class="pageNav">
        	<nav aria-label="Page navigation">
				  <ul class="pagination">
				    <li>
	                	<c:if test="${pageNum>1}">
	                		<a href="comm.html?cid=${cid}&title=${title}&page=${pageNum-1}" aria-label="Previous">
	                        	<span aria-hidden="true">&laquo;</span>
	                    	</a>
	                	</c:if>
	                    <c:if test="${pageNum<=1}">
	                		<a aria-label="Previous">
	                        	<span aria-hidden="true">&laquo;</span>
	                    	</a>
	                	</c:if>
                	</li>
                		<c:if test="${totalPages>0}">
                			<c:forEach var="p" begin="0" end="${totalPages-1}" varStatus="s">
		            			<li><a href="comm.html?cid=${cid}&title=${title}&page=${s.index+1}">${s.index+1}</a></li>
		                	</c:forEach>
                		</c:if>
	                <li>
	                	<c:if test="${pageNum<totalPages}">
	                		<a href="comm.html?cid=${cid}&title=${title}&page=${pageNum+1}" aria-label="Next">
	                        	<span aria-hidden="true">&raquo;</span>
	                    	</a>
	                	</c:if>
	                    <c:if test="${pageNum>=totalPages}">
	                		<a aria-label="Next">
	                        	<span aria-hidden="true">&raquo;</span>
	                    	</a>
	                	</c:if>
                	</li>
				  </ul>
			</nav>
        </div>
    </div>
</div>
</body>
</html>